Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize proc macros generating macro_rules items #64035

Merged
merged 2 commits into from Oct 15, 2019

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Aug 31, 2019

Fn-like and attribute proc macros can now generate macro_rules items.

cc #54727

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 31, 2019
@Centril Centril added needs-fcp This change is insta-stable, so needs a completed FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Aug 31, 2019
@Centril Centril added this to the 1.39 milestone Aug 31, 2019
@Centril Centril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 31, 2019
@JohnCSimon
Copy link
Member

Ping from triage - @petrochenkov this has sat idle for 7 days, can you please post the status of this PR?

thank you!

@petrochenkov
Copy link
Contributor Author

Busy week, I'll get to it ~next weekend.

@JohnTitor
Copy link
Member

Ping from triage: @petrochenkov any updates on this?

@JohnCSimon
Copy link
Member

Ping from triage.
@petrochenkov Just letting you know, this has sat idle for the last three weeks.
Thank you.

@petrochenkov petrochenkov force-pushed the stabmacgen branch 2 times, most recently from 92aa55c to 2cb35b0 Compare September 22, 2019 14:56
@petrochenkov
Copy link
Contributor Author

Stabilization report

Function-like macros and attribute macros can now generate macro_rules items.

For historical reasons this feature was never gated for derive macros (which were stabilized much earlier than other macro kinds).
So if people need to generate macro_rules, they usually just generate derives expanding to macro_rules instead of generating macro_rules directly.
As a result, the feature is de-facto stable and is actively relied upon by the ecosystem, at least through the proc_macro_hack crate.

Stable proc macros can only use transparent "call-site" hygiene, so in the basic case of a macro_rules item generated by a transparent macro, the item will behave as if it was copy-pasted into the call site.
So, names produced by expanding that macro_rules item will behave as if the item was written directly - local variables and labels will be hygienic, other names will be unhygienic and $crate will refer to the crate containing the macro_rules item, not to the proc macro crate.
This behavior is pretty intuitive and we didn't receive reports of bugs or unexpected behavior in this area, AFAIK.
If you want some specific cases tested, please leave a comment.

If some hygiene rules change in the future, they will most probably affect corner cases with some complex nesting and interactions between various kinds of hygiene mixed.
It will affect people to the same extent whether we stabilize macro_rules-generating fn-like and attribute macros or not, because they will affect derives anyway.

@petrochenkov petrochenkov changed the title [WIP] Stabilize proc macros generating macro_rules items Stabilize proc macros generating macro_rules items Sep 22, 2019
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 22, 2019
Copy link
Member

@eddyb eddyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty straight-forward stabilization, r=me once the decision has been taken.

@oli-obk oli-obk added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). I-nominated and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 25, 2019
@Centril Centril modified the milestones: 1.39, 1.40 Sep 26, 2019
@Centril
Copy link
Contributor

Centril commented Sep 26, 2019

r? @pnkfelix

@rust-highfive rust-highfive assigned pnkfelix and unassigned eddyb Sep 26, 2019
@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Oct 5, 2019
@rfcbot
Copy link

rfcbot commented Oct 5, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Oct 5, 2019
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Oct 15, 2019
@rfcbot
Copy link

rfcbot commented Oct 15, 2019

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Oct 15, 2019
@petrochenkov
Copy link
Contributor Author

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Oct 15, 2019

📌 Commit d80be3b has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 15, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 15, 2019
Stabilize proc macros generating `macro_rules` items

Fn-like and attribute proc macros can now generate `macro_rules` items.

cc rust-lang#54727
Centril added a commit to Centril/rust that referenced this pull request Oct 15, 2019
Stabilize proc macros generating `macro_rules` items

Fn-like and attribute proc macros can now generate `macro_rules` items.

cc rust-lang#54727
bors added a commit that referenced this pull request Oct 15, 2019
Rollup of 4 pull requests

Successful merges:

 - #64035 (Stabilize proc macros generating `macro_rules` items)
 - #65376 (syntax: misc extractions)
 - #65426 (Remove custom `PartialEq` impls for `LocalInternedString`.)
 - #65428 (Refactor: Rename `db` locals to `diag`)

Failed merges:

r? @ghost
@bors bors merged commit d80be3b into rust-lang:master Oct 15, 2019
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jan 6, 2020
Version 1.40.0 (2019-12-19)
===========================

Language
--------
- [You can now use tuple `struct`s and tuple `enum` variant's constructors in
  `const` contexts.][65188] e.g.

  ```rust
  pub struct Point(i32, i32);

  const ORIGIN: Point = {
      let constructor = Point;

      constructor(0, 0)
  };
  ```

- [You can now mark `struct`s, `enum`s, and `enum` variants with the `#[non_exhaustive]` attribute to
  indicate that there may be variants or fields added in the future.][64639]
  For example this requires adding a wild-card branch (`_ => {}`) to any match
  statements on a non-exhaustive `enum`. [(RFC 2008)]
- [You can now use function-like procedural macros in `extern` blocks and in
  type positions.][63931] e.g. `type Generated = macro!();`
- [Function-like and attribute procedural macros can now emit
  `macro_rules!` items, so you can now have your macros generate macros.][64035]
- [The `meta` pattern matcher in `macro_rules!` now correctly matches the modern
  attribute syntax.][63674] For example `(#[$m:meta])` now matches `#[attr]`,
  `#[attr{tokens}]`, `#[attr[tokens]]`, and `#[attr(tokens)]`.

Compiler
--------
- [Added tier 3 support\* for the
  `thumbv7neon-unknown-linux-musleabihf` target.][66103]
- [Added tier 3 support for the
  `aarch64-unknown-none-softfloat` target.][64589]
- [Added tier 3 support for the `mips64-unknown-linux-muslabi64`, and
  `mips64el-unknown-linux-muslabi64` targets.][65843]

\* Refer to Rust's [platform support page][forge-platform-support] for more
  information on Rust's tiered platform support.

Libraries
---------
- [The `is_power_of_two` method on unsigned numeric types is now a `const` function.][65092]

Stabilized APIs
---------------
- [`BTreeMap::get_key_value`]
- [`HashMap::get_key_value`]
- [`Option::as_deref_mut`]
- [`Option::as_deref`]
- [`Option::flatten`]
- [`UdpSocket::peer_addr`]
- [`f32::to_be_bytes`]
- [`f32::to_le_bytes`]
- [`f32::to_ne_bytes`]
- [`f64::to_be_bytes`]
- [`f64::to_le_bytes`]
- [`f64::to_ne_bytes`]
- [`f32::from_be_bytes`]
- [`f32::from_le_bytes`]
- [`f32::from_ne_bytes`]
- [`f64::from_be_bytes`]
- [`f64::from_le_bytes`]
- [`f64::from_ne_bytes`]
- [`mem::take`]
- [`slice::repeat`]
- [`todo!`]

Cargo
-----
- [Cargo will now always display warnings, rather than only on
  fresh builds.][cargo/7450]
- [Feature flags (except `--all-features`) passed to a virtual workspace will
  now produce an error.][cargo/7507] Previously these flags were ignored.
- [You can now publish `dev-dependencies` without including
  a `version`.][cargo/7333]

Misc
----
- [You can now specify the `#[cfg(doctest)]` attribute to include an item only
  when running documentation tests with `rustdoc`.][63803]

Compatibility Notes
-------------------
- [As previously announced, any previous NLL warnings in the 2015 edition are
  now hard errors.][64221]
- [The `include!` macro will now warn if it failed to include the
  entire file.][64284] The `include!` macro unintentionally only includes the
  first _expression_ in a file, and this can be unintuitive. This will become
  either a hard error in a future release, or the behavior may be fixed to include all expressions as expected.
- [Using `#[inline]` on function prototypes and consts now emits a warning under
  `unused_attribute` lint.][65294] Using `#[inline]` anywhere else inside traits
  or `extern` blocks now correctly emits a hard error.

[65294]: rust-lang/rust#65294
[66103]: rust-lang/rust#66103
[65843]: rust-lang/rust#65843
[65188]: rust-lang/rust#65188
[65092]: rust-lang/rust#65092
[64589]: rust-lang/rust#64589
[64639]: rust-lang/rust#64639
[64221]: rust-lang/rust#64221
[64284]: rust-lang/rust#64284
[63931]: rust-lang/rust#63931
[64035]: rust-lang/rust#64035
[63674]: rust-lang/rust#63674
[63803]: rust-lang/rust#63803
[cargo/7450]: rust-lang/cargo#7450
[cargo/7507]: rust-lang/cargo#7507
[cargo/7525]: rust-lang/cargo#7525
[cargo/7333]: rust-lang/cargo#7333
[(rfc 2008)]: https://rust-lang.github.io/rfcs/2008-non-exhaustive.html
[`f32::to_be_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.to_be_bytes
[`f32::to_le_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.to_le_bytes
[`f32::to_ne_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.to_ne_bytes
[`f64::to_be_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.to_be_bytes
[`f64::to_le_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.to_le_bytes
[`f64::to_ne_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.to_ne_bytes
[`f32::from_be_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.from_be_bytes
[`f32::from_le_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.from_le_bytes
[`f32::from_ne_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.from_ne_bytes
[`f64::from_be_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.from_be_bytes
[`f64::from_le_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.from_le_bytes
[`f64::from_ne_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.from_ne_bytes
[`option::flatten`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.flatten
[`option::as_deref`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.as_deref
[`option::as_deref_mut`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.as_deref_mut
[`hashmap::get_key_value`]: https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.get_key_value
[`btreemap::get_key_value`]: https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.get_key_value
[`slice::repeat`]: https://doc.rust-lang.org/std/primitive.slice.html#method.repeat
[`mem::take`]: https://doc.rust-lang.org/std/mem/fn.take.html
[`udpsocket::peer_addr`]: https://doc.rust-lang.org/std/net/struct.UdpSocket.html#method.peer_addr
[`todo!`]: https://doc.rust-lang.org/std/macro.todo.html
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jan 14, 2020
Version 1.40.0 (2019-12-19)
===========================

Language
--------
- [You can now use tuple `struct`s and tuple `enum` variant's constructors in
  `const` contexts.][65188] e.g.

  ```rust
  pub struct Point(i32, i32);

  const ORIGIN: Point = {
      let constructor = Point;

      constructor(0, 0)
  };
  ```

- [You can now mark `struct`s, `enum`s, and `enum` variants with the `#[non_exhaustive]` attribute to
  indicate that there may be variants or fields added in the future.][64639]
  For example this requires adding a wild-card branch (`_ => {}`) to any match
  statements on a non-exhaustive `enum`. [(RFC 2008)]
- [You can now use function-like procedural macros in `extern` blocks and in
  type positions.][63931] e.g. `type Generated = macro!();`
- [Function-like and attribute procedural macros can now emit
  `macro_rules!` items, so you can now have your macros generate macros.][64035]
- [The `meta` pattern matcher in `macro_rules!` now correctly matches the modern
  attribute syntax.][63674] For example `(#[$m:meta])` now matches `#[attr]`,
  `#[attr{tokens}]`, `#[attr[tokens]]`, and `#[attr(tokens)]`.

Compiler
--------
- [Added tier 3 support\* for the
  `thumbv7neon-unknown-linux-musleabihf` target.][66103]
- [Added tier 3 support for the
  `aarch64-unknown-none-softfloat` target.][64589]
- [Added tier 3 support for the `mips64-unknown-linux-muslabi64`, and
  `mips64el-unknown-linux-muslabi64` targets.][65843]

\* Refer to Rust's [platform support page][forge-platform-support] for more
  information on Rust's tiered platform support.

Libraries
---------
- [The `is_power_of_two` method on unsigned numeric types is now a `const` function.][65092]

Stabilized APIs
---------------
- [`BTreeMap::get_key_value`]
- [`HashMap::get_key_value`]
- [`Option::as_deref_mut`]
- [`Option::as_deref`]
- [`Option::flatten`]
- [`UdpSocket::peer_addr`]
- [`f32::to_be_bytes`]
- [`f32::to_le_bytes`]
- [`f32::to_ne_bytes`]
- [`f64::to_be_bytes`]
- [`f64::to_le_bytes`]
- [`f64::to_ne_bytes`]
- [`f32::from_be_bytes`]
- [`f32::from_le_bytes`]
- [`f32::from_ne_bytes`]
- [`f64::from_be_bytes`]
- [`f64::from_le_bytes`]
- [`f64::from_ne_bytes`]
- [`mem::take`]
- [`slice::repeat`]
- [`todo!`]

Cargo
-----
- [Cargo will now always display warnings, rather than only on
  fresh builds.][cargo/7450]
- [Feature flags (except `--all-features`) passed to a virtual workspace will
  now produce an error.][cargo/7507] Previously these flags were ignored.
- [You can now publish `dev-dependencies` without including
  a `version`.][cargo/7333]

Misc
----
- [You can now specify the `#[cfg(doctest)]` attribute to include an item only
  when running documentation tests with `rustdoc`.][63803]

Compatibility Notes
-------------------
- [As previously announced, any previous NLL warnings in the 2015 edition are
  now hard errors.][64221]
- [The `include!` macro will now warn if it failed to include the
  entire file.][64284] The `include!` macro unintentionally only includes the
  first _expression_ in a file, and this can be unintuitive. This will become
  either a hard error in a future release, or the behavior may be fixed to include all expressions as expected.
- [Using `#[inline]` on function prototypes and consts now emits a warning under
  `unused_attribute` lint.][65294] Using `#[inline]` anywhere else inside traits
  or `extern` blocks now correctly emits a hard error.

[65294]: rust-lang/rust#65294
[66103]: rust-lang/rust#66103
[65843]: rust-lang/rust#65843
[65188]: rust-lang/rust#65188
[65092]: rust-lang/rust#65092
[64589]: rust-lang/rust#64589
[64639]: rust-lang/rust#64639
[64221]: rust-lang/rust#64221
[64284]: rust-lang/rust#64284
[63931]: rust-lang/rust#63931
[64035]: rust-lang/rust#64035
[63674]: rust-lang/rust#63674
[63803]: rust-lang/rust#63803
[cargo/7450]: rust-lang/cargo#7450
[cargo/7507]: rust-lang/cargo#7507
[cargo/7525]: rust-lang/cargo#7525
[cargo/7333]: rust-lang/cargo#7333
[(rfc 2008)]: https://rust-lang.github.io/rfcs/2008-non-exhaustive.html
[`f32::to_be_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.to_be_bytes
[`f32::to_le_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.to_le_bytes
[`f32::to_ne_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.to_ne_bytes
[`f64::to_be_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.to_be_bytes
[`f64::to_le_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.to_le_bytes
[`f64::to_ne_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.to_ne_bytes
[`f32::from_be_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.from_be_bytes
[`f32::from_le_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.from_le_bytes
[`f32::from_ne_bytes`]: https://doc.rust-lang.org/std/primitive.f32.html#method.from_ne_bytes
[`f64::from_be_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.from_be_bytes
[`f64::from_le_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.from_le_bytes
[`f64::from_ne_bytes`]: https://doc.rust-lang.org/std/primitive.f64.html#method.from_ne_bytes
[`option::flatten`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.flatten
[`option::as_deref`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.as_deref
[`option::as_deref_mut`]: https://doc.rust-lang.org/std/option/enum.Option.html#method.as_deref_mut
[`hashmap::get_key_value`]: https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.get_key_value
[`btreemap::get_key_value`]: https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.get_key_value
[`slice::repeat`]: https://doc.rust-lang.org/std/primitive.slice.html#method.repeat
[`mem::take`]: https://doc.rust-lang.org/std/mem/fn.take.html
[`udpsocket::peer_addr`]: https://doc.rust-lang.org/std/net/struct.UdpSocket.html#method.peer_addr
[`todo!`]: https://doc.rust-lang.org/std/macro.todo.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants